package cn.kgc.controller;

import cn.kgc.pojo.Student;
import cn.kgc.pojo.User;
import cn.kgc.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @ClassName UserController
 * @Description TODO
 * @Author yaozhaobao
 * @Date 2020/11/13 15:44
 * @Version 1.0
 **/
@RestController
@RequestMapping("/sys")
@Slf4j
public class UserController {

    @Autowired
    Student student;

    @Autowired
    UserService userService;


    @RequestMapping("/list")
    public String userlist(){
        return "hello "+student.getName()+",hello daizhishun,hello zhangwenbing";
    }


    @RequestMapping("/test")
    public String userName(@RequestParam("id")String id, HttpSession session){
        session.setAttribute("LOGIN_KEY",id);
        return "hello"+ userService.getUserName(Integer.parseInt(id));
    }

    @RequestMapping("/addUser")

    public String addUser(@RequestParam String name,@RequestParam String password){
        log.info("入参数:name:{},password{}",name,password);
        User user = new User();
        user.setUserName(name);
        user.setUserPassword(password);
        if(userService.addUser(user)>=1){
            return "插入成功";
        }else {
            return  "插入失败";
        }
    }




}
